package com.fancy.controller;

import com.fancy.pojo.BaseResult;
import com.fancy.pojo.category.Music;
import com.fancy.pojo.dto.MusicDto;
import com.fancy.service.MusicService;
import com.github.pagehelper.PageInfo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

@RestController
@RequestMapping("/category")
public class CategoryMusicController {

    @Autowired
    MusicService musicService;

    @RequestMapping("/selectAllMusic")
    public List<Music> selectAllMusic(){
        return musicService.selectAllMusic();
    }

//    @RequestMapping("/selectMusicById/{id}")
//    public Music selectMusicById(@PathVariable("id") String id){
//        return musicService.selectMusicById(Integer.parseInt(id));
//    }
    @PostMapping("/selectMusicById/{id}")
    public MusicDto selectMusicById(@PathVariable("id") Integer id){
        return musicService.selectMusicById(id);
    }


    //查询所有数据
    @RequestMapping("/findAllMusic/{page}/{size}")
    public PageInfo<MusicDto> findAllMusic(@PathVariable("page") Integer page,
                                       @PathVariable("size") Integer size){
        return musicService.findAllMusicPage(page,size);
    }
//    @RequestMapping("/findMusicById/{id}")
//    public Music findMusicById(@PathVariable("id") Integer id){
//        return musicService.findMusicById(id);
//    }

    //根据专辑id查询
    @RequestMapping("/selectMusicByAlbumId/{id}")
    public List<MusicDto> selectMusicByAlbumId(@PathVariable("id") Integer id){
        return musicService.selectMusicByAlbumId(id);
    }
    @GetMapping("/findMusicListByPage/{page}/{size}")
    public PageInfo<Music> findMusicListByPage(
            @PathVariable("page") Integer page,
            @PathVariable("size") Integer size){
        return musicService.findMusicListByPage(page,size);
    }

    //根据音乐类型来查询歌曲的所有信息
    @RequestMapping("/findMusicByTypeId/{id}")
    public List<MusicDto> findMusicByTypeId(@PathVariable("id") Integer id){
        return musicService.findMusicByTypeId(id);
    }
    //根据语言来查询歌曲所有信息
    @RequestMapping("/findMusicByLanguageId/{id}")
    public List<MusicDto> findMusicByLanguageId(@PathVariable("id") Integer id){
        return musicService.findMusicByLanguageId(id);
    }

    //根据音乐名查询音乐
    @RequestMapping("/findMusicByName/{musicName}")
    public BaseResult<Music> findMusicByName(@PathVariable("musicName") String musicName){

        BaseResult baseResult = new BaseResult();

        if (musicName==null){
            //信息输入错误，返回所有数据
            baseResult.setMessage("信息输入错误");
            return baseResult;
        }

        List<Music> musicList=musicService.findMusicByName(musicName);

        if(musicList==null){
            baseResult.setMessage("歌曲信息未找到");
            return baseResult;
        }

        baseResult.setMessage("歌曲信息已找到");
        return baseResult;

    }

    //动态获取查询
    @PostMapping("/getMusicById")
    public List<Music> getMusicById(@RequestBody Map map){
//        Map hashMap = new HashMap();
//        hashMap.put(map.getMusicTypeId());

//       return musicService.getMusicById((Integer) map.get("musicTypeId"),(Integer)map.get("singerId"),(Integer)map.get("languageId"));

        return musicService.getMusicById(map);

    }

    //map传参之后的分页



}
